#!/usr/bin/env python

max_array_length=10;
num_delay_to_loss=0;
num_loss_to_delay=0;

#num_delay_given_loss[x] means number of loss->delay occurrences seen when given previous loss episode=x
num_delay_given_loss = [0]*(max_array_length);
num_loss_given_delay = [0]*(max_array_length);

#I/O
fi = open("/Volumes/Data/switch_project/exp16/1000M/900M/1/1_flow_delay_loss_episode.txt", "r");
fh = open("/Volumes/Data/switch_project/exp16/1000M/900M/1/probability_loss_delay_episode.txt", "w")

print "Hello, World!" 

prev_value=1;

for line in fi:
	cur_value=int(line);	
	if(cur_value<0 and prev_value>0):
		num_delay_to_loss=num_delay_to_loss+1;
		num_loss_given_delay[prev_value]=num_loss_given_delay[prev_value]+1;
	elif(cur_value>0 and prev_value<0):
		num_loss_to_delay=num_loss_to_delay+1;
		num_delay_given_loss[-prev_value]=num_delay_given_loss[-prev_value]+1;
	prev_value = cur_value;

print 'num_delay_to_loss = ', num_delay_to_loss, 'num_loss_to_delay = ', num_loss_to_delay, '\n'; 
print num_delay_given_loss;
print num_loss_given_delay;

#output loss_given_delay
for i in range(len(num_loss_given_delay)):
	temp = float(num_loss_given_delay[i])/float(num_delay_to_loss);
	fh.write(str(temp));
	fh.write(' ');
fh.write("\n");

#output delay_given_loss
for i in range(len(num_delay_given_loss)):
	temp = float(num_delay_given_loss[i])/float(num_loss_to_delay);
	fh.write(str(temp));
	fh.write(' ');
fh.write("\n");

fi.close();
fh.close();